package com.yls.except.service.impl;

import com.yls.except.dao.*;
import com.yls.except.service.UserService;
import com.yls.except.task.RedisCash;
import com.yls.except.util.*;
import com.yls.except.util.exception.CustomException;
import com.yls.except.util.imgfile.ImgFileHandle;
import com.yls.except.util.kuaidiniao.KdApiOrderDistinguish;
import com.yls.except.util.kuaidiniao.KdniaoTrackQueryAPI;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 用户serviceimpl
 */
@Service
@Repository(value = "userService")
public class UserServiceImpl implements UserService {

    @Resource(name = "userDao")
    private UserDao userDao;
    @Resource(name = "systemDao")
    private SystemDao systemDao;
    @Resource(name = "indentDao")
    private IndentDao indentDao;


    @Override
    public Map<String, Object> insertUser(String openid, String nickname, String sex, String head, String reqip, String invitecode, String realPath) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("binding_num", openid);
        map.put("binding_type", "1");
        Map<String, Object> threeBanding = userDao.selectThreeInfo(map);  //获取三方绑定信息
        if (StringIsempty.isallempty(nickname))
            nickname = "";
        if (StringIsempty.isallempty(sex))
            sex = "1";
        if (StringIsempty.isallempty(head))
            head = "";
        if (StringIsempty.isallempty(reqip))
            reqip = "";
        int tag;
        long time = new Date().getTime();
        String uid;
        String usertype;
        String item = ImgProperties.getConstan("itemname");  //获取项目名称
        //判断该openid是否已注册，若注册，则直接登录，否注册
        if (StringIsempty.isNullMap(threeBanding)) {
            Map<String, Object> userinfo = new HashMap<>();
            userinfo.put("nickname", nickname);
            userinfo.put("phone", "");
            userinfo.put("userpwd", "");
            userinfo.put("username", "");
            userinfo.put("headimg", head);
            userinfo.put("sex", sex);
            userinfo.put("birthday", time + "");
            userinfo.put("age", "0");
            userinfo.put("type", "0");
            userinfo.put("registertime", time + "");
            userinfo.put("registertip", reqip);


            userinfo.put("isdisabled", "1");
            tag = userDao.insertUser(userinfo);
            if (tag <= 0)
                throw new CustomException();
            uid = userinfo.get("uid") + "";
            String secne_str = HexString.insertstr(uid, 2, item);
            secne_str = HexString.encode(secne_str);
            //判断用户邀请二维码地址是否存在，若不存在则修改
            if (updateUserInviteUrl(map, userinfo, secne_str, realPath)) return map;
            usertype = "0";
            threeBanding = new HashMap<String, Object>();
            threeBanding.put("uid", uid);
            threeBanding.put("binding_num", openid);
            threeBanding.put("binding_type", "1");
            threeBanding.put("nick_name", nickname);
            threeBanding.put("sex", sex);
            threeBanding.put("binding_date", time + "");
            threeBanding.put("head", head);
            threeBanding.put("isdisabled", "1");
            threeBanding.put("relieve_date", "0");
            tag = userDao.insertThreeBing(threeBanding);
            if (tag <= 0)
                throw new CustomException();
            Map<String, String> userloginlog = new HashMap<String, String>();
            userloginlog.put("uid", uid);
            userloginlog.put("currentlng", "0");
            userloginlog.put("currentlat", "0");
            userloginlog.put("loginlng", "0");
            userloginlog.put("loginlat", "0");
            userloginlog.put("lastloginlng", "0");
            userloginlog.put("lastloginlat", "0");
            userloginlog.put("logintime", time + "");
            userloginlog.put("loginip", reqip);
            userloginlog.put("exittime", "0");
            userloginlog.put("exitip", "");
            userloginlog.put("lastexittime", "0");
            userloginlog.put("lastexitip", "0");
            userloginlog.put("logindate", "0");
            userloginlog.put("logindateavg", "0");
            userloginlog.put("firstlogintime", time + "");
            userloginlog.put("firstloginip", reqip);
            userloginlog.put("state", "1");
            userloginlog.put("lastlogintime", time + "");
            userloginlog.put("lastloginip", reqip);
            userloginlog.put("count", "1");
            userloginlog.put("isdisabled", "1");
            tag = userDao.insertUserLogin(userloginlog);
            if (tag <= 0)
                throw new CustomException();

            if (!StringIsempty.isallempty(invitecode)) {
                invitecode = HexString.decode(invitecode);
                invitecode = HexString.removestr(invitecode, 2, item, "");
                if (!StringIsempty.isallempty(invitecode)) {
                    Map<String, Object> inviteuser = userDao.selectUserInfoByUid(invitecode);
                    if (!StringIsempty.isNullMap(inviteuser)) {
                        Map<String, Object> invite = new HashMap<String, Object>();
                        invite.put("invite_id", ValueJude.getUuid());
                        invite.put("invite_uid", invitecode);
                        invite.put("uid", uid);
                        invite.put("addtime", time);
                        invite.put("addip", reqip);
                        invite.put("isdisabled", 1);
                        tag = userDao.insertInviteInfo(invite);
                    }
                }
            }
        } else {
            uid = threeBanding.get("uid") + "";
            Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
            usertype = userinfo.get("type") + "";
            if (StringIsempty.isNullMap(userinfo)) {
                map.put("tag", "-1");
                return map;
            }

            String invite_url = userinfo.get("invite_url") + "";
            if (StringIsempty.isallempty(invite_url)) {
                String secne_str = HexString.insertstr(uid, 2, item);
                secne_str = HexString.encode(secne_str);
                if (updateUserInviteUrl(map, userinfo, secne_str, realPath)) return map;
            }

            Map<String, Object> userloginlog = userDao.selectUserLoginLogByUid(uid);
            userloginlog.put("logintime", time + "");
            userloginlog.put("loginip", reqip);
            userloginlog.put("state", "1");
            int count = Integer.parseInt(userloginlog.get("count") + "");
            count++;
            userloginlog.put("count", count + "");
            userloginlog.put("lastlogintime", time + "");
            userloginlog.put("lastloginip", reqip);
            tag = userDao.updateUserLoginLogInfo(userloginlog);
        }
        if (tag <= 0)
            throw new CustomException();

        String token = ValueJude.getUuid();  //获取一个随机数
        String utoken = HexString.insertstr(token, 6, item);  //向token字符串第6个位置添加item字符串
        utoken = HexString.encode(utoken);  //加密
        BaseServiceImpl.removeUserTokenByUid(uid);
        List<String> list = new ArrayList<String>();
        list.add(token);
        RedisCash.redisList("exceptuserToken", list);
        Map<String, String> userMap = RedisCash.getMap(uid);
        userMap.put("time", new Date().getTime() + "");
        userMap.put("uid", uid);
        userMap.put("openid", openid);
        userMap.put("type", usertype);
        RedisCash.redisMap(token, userMap);
        map = new HashMap<String, Object>();
        map.put("token", utoken);
        map.put("usertype", usertype);
        map.put("uid", uid);
        map.put("tag", "1");
        return map;
    }

    private boolean updateUserInviteUrl(Map<String, Object> map, Map<String, Object> userinfo, String secne_str, String realPath) {
        int tag;
        Map<String, String> accesstoken = WeiXinUtils.getAccessToken(ConstantUtil.APP_ID, ConstantUtil.APP_SECRET);
        if (!StringIsempty.isNullMap(accesstoken)) {
            Map<String, Object> getTicket = WeiXinUtils.createTicket(accesstoken.get("access_token"), secne_str);
            if (!StringIsempty.isNullMap(getTicket)) {
                String str = WeiXinUtils.showqrcode(getTicket.get("ticket") + "");

                String src = ImgProperties.getimg("headimg");
                String inviteurl = ImgFileHandle.uploadimg(str, realPath, src);
                userinfo.put("invite_url", inviteurl);
                tag = userDao.updateUserInfo(userinfo);
                if (tag <= 0) {
                    map.put("tag", -2);
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public Map<String, Object> selectUserInfoByUid(String uid) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return null;
        Map<String, Object> auth = userDao.selectUserAuthInfoByUid(uid);
        if (StringIsempty.isNullMap(auth)) {
            userinfo.put("isauth", false);
            userinfo.put("name", "");
            userinfo.put("card", "");
        } else {
            userinfo.put("isauth", true);
            userinfo.put("name", auth.get("name") + "");
            userinfo.put("card", auth.get("card") + "");
        }

        List<Map<String, Object>> list = indentDao.selectIndentListInfoByUid(uid);
        if(StringIsempty.isNullList(list))
            userinfo.put("logistic", "");
        else {
            Map<String, Object> map = new HashMap<String, Object>();
            for (int i = 0; i < list.size(); i ++) {
                Map<String, Object> indentinfo = list.get(i);
                if(!StringIsempty.isNullMap(indentinfo)) {
                    Map<String, Object> logistic = indentDao.selectLogisticsByIndentNum(indentinfo.get("indent_num") + "");
                    String logistics_num = "";
                    if(!StringIsempty.isNullMap(logistic)) {
                        logistics_num = logistic.get("logistics_num") + "";
                        String result = KdApiOrderDistinguish.getOrderTracesByJson(logistics_num);
                        if(!StringIsempty.isallempty(result)) {
                            Map<String, Object> resultMap = GeneralResult.jsonStrToMap(result);
                            if(!StringIsempty.isNullMap(resultMap)) {
                                JSONArray jsonArray = (JSONArray) resultMap.get("Shippers");
                                try {
                                    if(jsonArray != null && jsonArray.length() > 0) {
                                        String ShipperCode = ((JSONObject)jsonArray.get(0)).get("ShipperCode") + "";
                                        result = KdniaoTrackQueryAPI.getOrderTracesByJson(ShipperCode, logistics_num);
                                        if(!StringIsempty.isallempty(result)) {
                                            resultMap = GeneralResult.jsonStrToMap(result);
                                            if(!StringIsempty.isNullMap(resultMap)) {
                                                jsonArray = (JSONArray) resultMap.get("Traces");
                                                String State = resultMap.get("State") + "";
                                                if(jsonArray != null && jsonArray.length() > 0) {
                                                    String AcceptTime = ((JSONObject) jsonArray.get(0)).getString("AcceptTime");
                                                    String AcceptStation = ((JSONObject) jsonArray.get(0)).getString("AcceptStation");
                                                    if(StringIsempty.isNullMap(map)) {
                                                        map.put("indentnum", indentinfo.get("indent_num") + "");
                                                        map.put("AcceptTime", AcceptTime);
                                                        map.put("AcceptStation", AcceptStation);
                                                        map.put("State", State);
                                                    } else {
                                                        long time = DateStringLong.stringToLong(AcceptTime, "yyyy-MM-dd HH:mm:ss");
                                                        long befortime = DateStringLong.stringToLong(map.get("befortime") + "", "yyyy-MM-dd HH:mm:ss");
                                                        if(time > befortime) {
                                                            map.put("indentnum", indentinfo.get("indent_num") + "");
                                                            map.put("AcceptTime", AcceptTime);
                                                            map.put("AcceptStation", AcceptStation);
                                                            map.put("State", State);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }

            if(StringIsempty.isNullMap(map))
                userinfo.put("logistic", "");
            else {
                String indentnum = map.get("indentnum") + "";
                List<Map<String, Object>> shoplist = indentDao.selectIndentShopInfoByIndentNum(indentnum);
                if(!StringIsempty.isNullList(shoplist))
                    map.put("img", shoplist.get(0).get("img"));
                else
                    map.put("img", "");
                map.put("time", DateStringLong.longToString(DateStringLong.stringToLong(map.get("AcceptTime") + "", "yyyy-MM-dd HH:mm:ss"), "MM-dd"));
                String State = map.get("State") + "";
                if("2".equals(State))
                    map.put("statedesc", "在途中");
                else if("3".equals(State))
                    map.put("statedesc", "已签收");
                else
                    map.put("statedesc", "问题件");
                userinfo.put("logistic", map);
            }
        }
        userinfo.put("birthday", DateStringLong.longToString(Long.parseLong(userinfo.get("birthday") + ""), "yyyy-MM-dd"));
        userinfo.put("tag", 1);
        return userinfo;
    }

    @Override
    public int updateUserinfo(String uid, String headimg, String nickname, String sex, String birthday) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return -13;
        if (!StringIsempty.isallempty(headimg))
            userinfo.put("headimg", headimg);
        if (!StringIsempty.isallempty(nickname))
            userinfo.put("nickname", nickname);
        if (!StringIsempty.isallempty(sex))
            userinfo.put("sex", sex);
        if(!StringIsempty.isallempty(birthday))
            userinfo.put("birthday", DateStringLong.stringToLong(birthday, "yyyy-MM-dd"));
        return userDao.updateUserInfo(userinfo);
    }

    @Override
    public int insertPhoneCode(String phone, String type, String uid, String addip) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return -13;
        if ("0".equals(type) && !StringIsempty.isallempty(userinfo.get("phone") + ""))
            return -26;  //已绑定手机号
        if ("1".equals(type) && (StringIsempty.isallempty(userinfo.get("phone") + "") || !phone.equals(userinfo.get("phone") + "")))
            return -6;  //与绑定手机号不一致
        String yzcode = (new Random().nextInt(899999) + 100000) + "";
        Map<String, Object> map = PhoneMessage.phonesendmessage(yzcode, phone, type);
        if (map == null) {
            return 0;
        }
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("code", "000000");
//        map.put("msg", "获取验证码");
        String msg = map.get("msg") + "";
        String code = map.get("code") + "";

        map = new HashMap<String, Object>();
        map.put("phonecode_id", ValueJude.getUuid());  //验证码记录id
        map.put("phone", phone); //电话号码
        if (StringIsempty.isallempty(uid))
            uid = "0";
        map.put("uid", uid); //电话号码
        map.put("code", code); //验证码
        map.put("message", msg); //信息
        map.put("addtime", new Date().getTime() / 1000);  //新增时间
        map.put("addip", addip); //新增ip
        map.put("status", code); //状态
        map.put("returncode", code); //获取验证码返回值
        map.put("type", type); //类型
        int tag = systemDao.insertPhoneCode(map); //新增获取验证码记录
        if (tag <= 0)  //判断新增是否成功
            return 0; //新增失败
        if (!"000000".equals(code))
            return -25;
        else {
            GetCode.getcode(phone, yzcode, type);
            return Integer.parseInt(yzcode);
        }
    }

    @Override
    public int updateBindingPhone(String uid, String phone) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return -13;
        if (!StringIsempty.isallempty(userinfo.get("phone") + ""))
            return -26;  //已绑定手机号
        userinfo.put("phone", phone);
        return userDao.updateUserInfo(userinfo);
    }

    @Override
    public int updateUserPwd(String uid, String phone, String pwd) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return -13;
        if (StringIsempty.isallempty(userinfo.get("phone") + "") || !phone.equals(userinfo.get("phone") + ""))
            return -6;  //与绑定手机号不一致
        String itemname = ImgProperties.getConstan("itemname");  //获取项目名
        pwd = HexString.insertstr(pwd, 4, itemname);  //在密码的第四个位置后加入项目名称
        pwd = GetMD5.MD5(pwd);  //给密码md5加密
        userinfo.put("userpwd", pwd);
        return userDao.updateUserInfo(userinfo);
    }

    @Override
    public List<Object> selectInviteInfoByUid(String uid, String page) {

        Map<String, Object> user = userDao.selectUserInfoByUid(uid);
        if(StringIsempty.isNullMap(user))
            return null;
        if("0".equals(user.get("type") + ""))
            return null;

        int nowpage = 0;
        if (!StringIsempty.isallempty(page))
            nowpage = Integer.parseInt(page);
        Map<String, Object> map = PageUtil.getNowPage(nowpage, 20);
        map.put("uid", uid);
        List<Map<String, Object>> invite = userDao.selectInviteInfo(map);
        List<Object> list = new ArrayList<Object>();
        if (!StringIsempty.isNullList(invite)) {
            for (int i = 0; i < invite.size(); i++) {
                Map<String, Object> inviteinfo = invite.get(i);
                if (StringIsempty.isNullMap(inviteinfo))
                    continue;
                Map<String, Object> proxyinfo = userDao.selectProxyMoneyByUid(inviteinfo);
                if (!StringIsempty.isNullMap(proxyinfo)) {
                    proxyinfo.put("indentmoney", ValueJude.getDecima(proxyinfo.get("indentmoney") + ""));
                    proxyinfo.put("percentage", ValueJude.getDecima(proxyinfo.get("percentage") + ""));
                } else {
                    proxyinfo.put("indentmoney", 0);
                    proxyinfo.put("percentage", 0);
                }
                list.add(proxyinfo);
            }
        }
        return list;
    }

    @Override
    public Map<String, Object> selectUserAccountByUid(String uid) {
        Map<String, Object> useraccount = userDao.selectUserAccountByUid(uid);
        Map<String, Object> map = new HashMap<String, Object>();
        if (useraccount == null)
            map.put("sparemoney", 0);
        else
            map.put("sparemoney", ValueJude.getDecima(useraccount.get("sparemoney") + ""));
        map.put("tag", 1);
        return map;
    }

    @Override
    public Map<String, Object> selectUserAuthInfoByUId(String uid) {
        Map<String, Object> auth = userDao.selectUserAuthInfoByUid(uid);
        if (StringIsempty.isNullMap(auth))
            return null;
        auth.put("tag", 1);
        return auth;
    }

    @Override
    public int insertUserAuth(String uid, String name, String card, String reqip) {
        Map<String, Object> auth = userDao.selectUserAuthInfoByUid(uid);
        if (!StringIsempty.isNullMap(auth))
            return -65;
        auth = new HashMap<String, Object>();
        auth.put("uid", uid);
        auth.put("name", name);
        auth.put("card", card);
        auth.put("addtime", new Date().getTime());
        auth.put("addip", reqip);
        auth.put("isdisabled", 1);
        return userDao.insertUserAuthInfo(auth);
    }

    @Override
    public int updateLoginOut(String uid, String loginoutip, int type) {
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);  //根据用户id查询用户个人信息
        if (userinfo == null)  //判断用户个人信息是否为空
            return 0;
        Map<String, Object> userlogin = userDao.selectUserLoginLogByUid(uid); //根据用户id查询用户登陆记录信息
        if (userlogin == null)  //判断用户登陆记录信息是否为空
            return 0;
        long exittime = Long.parseLong(userlogin.get("exittime") + "");  //获取用户上次退出时间
        String exitip = userlogin.get("exitip") + ""; //获取用户上次退出ip
        long nowtime = new Date().getTime();  //当前时间秒值
        long logintime = Long.parseLong(userlogin.get("logintime") + ""); // 登录时间
        long logindate = nowtime - logintime;  //登陆时长
        if (logindate <= 0)  //判断登陆时长是否小于0
            logindate = 0; //若登陆时长小于0则默认为0
        userinfo.put("jpushtag", "");  //删除用户的极光标识
        int tag = userDao.updateUserInfo(userinfo);  //用户用户个人信息
        if (tag <= 0) //判断是否修改成功
            return 0;
        long logindateavg = Long.parseLong(userlogin.get("logindateavg") + ""); // 平均登录时长
        int count = Integer.parseInt(userlogin.get("count") + ""); // 登录次数
        logindateavg = (logindateavg * count + logindate) / count; //最新平均登陆时长
        userlogin.put("exitdate", nowtime);  //本次退出时间
        userlogin.put("exitip", loginoutip); //本次退出ip
        userlogin.put("lastexitdate", exittime); //上次退出时间
        userlogin.put("lastexitip", exitip); //上次退出ip
        userlogin.put("state", type); //状态 2：手动退出 3：登陆超时系统退出
        userlogin.put("logindate", logindate); //本次登陆时长
        userlogin.put("logindateavg", logindateavg);  //平均登陆时长
        return userDao.updateUserLoginLogInfo(userlogin);
    }

    @Override
    public Map<String, Object> updateUserByOpenid(String openid, String reqip, String realPath) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("binding_num", openid);
        map.put("binding_type", "1");
        Map<String, Object> threeBanding = userDao.selectThreeInfo(map);  //获取三方绑定信息
        if (StringIsempty.isNullMap(threeBanding))
            return null;
        String uid = threeBanding.get("uid") + "";
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        String usertype = userinfo.get("type") + "";
        if (StringIsempty.isNullMap(userinfo)) {
            map.put("tag", "-1");
            return map;
        }
        long time = new Date().getTime();
        Map<String, Object> userloginlog = userDao.selectUserLoginLogByUid(uid);
        userloginlog.put("logintime", time + "");
        userloginlog.put("loginip", reqip);
        userloginlog.put("state", "1");
        int count = Integer.parseInt(userloginlog.get("count") + "");
        count++;
        userloginlog.put("count", count + "");
        userloginlog.put("lastlogintime", time + "");
        userloginlog.put("lastloginip", reqip);
        int tag = userDao.updateUserLoginLogInfo(userloginlog);
        if (tag <= 0) {
            map.put("tag", -2);
            return map;
        }

        String item = ImgProperties.getConstan("itemname");  //获取项目名称
        String secne_str = HexString.insertstr(uid, 2, item);
        secne_str = HexString.encode(secne_str);
        //判断用户邀请二维码地址是否存在，若不存在则修改
        String invite_url = userinfo.get("invite_url") + "";
        if (StringIsempty.isallempty(invite_url)) {
            if (updateUserInviteUrl(map, userinfo, secne_str, realPath)) return map;
        }

        String token = ValueJude.getUuid();  //获取一个随机数
        String utoken = HexString.insertstr(token, 6, item);  //向token字符串第6个位置添加item字符串
        utoken = HexString.encode(utoken);  //加密
        BaseServiceImpl.removeUserTokenByUid(uid);
        List<String> list = new ArrayList<String>();
        list.add(token);
        RedisCash.redisList("exceptuserToken", list);
        Map<String, String> userMap = RedisCash.getMap(uid);
        userMap.put("time", new Date().getTime() + "");
        userMap.put("uid", uid);
        userMap.put("type", usertype);
        userMap.put("openid", openid);
        RedisCash.redisMap(token, userMap);
        map = new HashMap<String, Object>();
        map.put("token", utoken);
        map.put("usertype", usertype);
        map.put("uid", uid);
        map.put("tag", "1");
        return map;
    }

    @Override
    public Map<String, Object> selectUserProxyInfoByUId(String uid) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> userinfo = userDao.selectUserInfoByUid(uid);
        if (StringIsempty.isNullMap(userinfo))
            return null;

        map.put("headimg", userinfo.get("headimg") + "");
        map.put("nickname", userinfo.get("nickname") + "");
        map.put("type", userinfo.get("type") + "");

        Map<String, Object> useraccount = userDao.selectUserAccountByUid(uid);
        if (StringIsempty.isNullMap(useraccount))
            map.put("sparemoney", 0);
        else
            map.put("sparemoney", ValueJude.getDecima(useraccount.get("sparemoney") + ""));

        getSystemSetInfo(map, "3", "first", 500, systemDao);
        getSystemSetInfo(map, "4", "second", 2000, systemDao);
        getSystemSetInfo(map, "5", "third", 5000, systemDao);
        getSystemSetInfo(map, "6", "forth", 10000, systemDao);

        map.put("tag", 1);
        return map;
    }

    private void getSystemSetInfo(Map<String, Object> map, String id, String key, int money, SystemDao systemDao) {
        Map<String, Object> systemset = systemDao.selectSystemSetInfoById(id);
        if (StringIsempty.isNullMap(systemset))
            map.put(key, money);
        else
            map.put(key, systemset.get("setvalue") + "");
    }
}